package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsGoodsAttributeMapper;
import com.qf.pojo.DtsGoodsAttribute;
import com.qf.service.DtsGoodsAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author ZhangYuJie
 * projectName:shop_manage
 * time:2022/5/17 21:22
 * description:
 */
@Service
public class DtsGoodsAttributeServiceImpl implements DtsGoodsAttributeService {
    @Autowired
    private DtsGoodsAttributeMapper goodsAttributeMapper;

    @Override
    public List<DtsGoodsAttribute> queryByGid(Integer goodsId) {
        QueryWrapper<DtsGoodsAttribute> wapper = new QueryWrapper<>();
        wapper.eq("goods_id", goodsId);
        wapper.eq("deleted", false);
        return goodsAttributeMapper.selectList(wapper);
    }

    @Override
    public void add(DtsGoodsAttribute goodsAttribute) {
        goodsAttribute.setAddTime(new Date());
        goodsAttribute.setUpdateTime(new Date());
        goodsAttributeMapper.insert(goodsAttribute);
    }

    @Override
    public void deleteByGid(Integer gid) {
        QueryWrapper<DtsGoodsAttribute> wapper = new QueryWrapper<>();
        wapper.eq("goods_id", gid);
        goodsAttributeMapper.delete(wapper);
    }
}
